<template>
  <div>
    <el-tag
      :key="tag.name"
      v-for="tag in tags"
      :closable="tag.name !== 'home'"
      :disable-transitions="false"
      @close="handleClose(tag)"
      size="small"
      @click="changeMenu(tag)"
      :effect="$route.name === tag.name ? 'dark' : 'plain'"
    >
      {{ tag.label }}
    </el-tag>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'Tab',
  data() {
    return {}
  },
  methods: {
    handleClose(tag) {
      // this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
      this.close(tag)
    },
    ...mapMutations({
      close: 'closeTab'
    }),
    changeMenu(item) {
      this.$router.push({ name: item.name }).catch(err => {
        err
      })
      this.$store.commit('selectMenu', item)
    }
  },
  computed: {
    ...mapState({
      tags: state => state.tab.tabsList
    })
  }
}
</script>

<style lang="scss" scoped>
.el-tag {
  margin-right: 20px;
  margin-top: 15px;
  margin-bottom: 15px;
  cursor: pointer;
}
</style>
